package imageSmoother

func imageSmoother(img [][]int) [][]int {
	row, col := len(img), len(img[0])
	res := [][]int{}
	for i := 0; i < row; i += 1 {
		tmp := []int{}
		for j := 0; j < col; j += 1 {
			sum, count, c_row, c_col := 0, 0, i+1, j+1
			for c_r := i - 1; c_r <= c_row; c_r += 1 {
				if c_r < 0 || c_r >= row {
					continue
				}
				for c_c := j - 1; c_c <= c_col; c_c += 1 {
					if c_c < 0 || c_c >= col {
						continue
					}
					sum += img[c_r][c_c]
					count += 1
				}

			}
			tmp = append(tmp, sum/count)
		}
		res = append(res, tmp)
	}
	return res
}
